package com.itcat.controller;/*
 * @Author: gonhsl
 * @Date:2022-04-04-9:58
 * */

import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsFlashPromotionSession;
import com.itcat.mysql.vo.SmsFlashPromotionSessionDetail;
import com.itcat.service.SmsFlashPromotionSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class SmsFlashPromotionSessionController {
    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * Description:获取全部场次
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @GetMapping("/list")
    public CommonResult list() {
        List<SmsFlashPromotionSession> smsFlashPromotionSessions = smsFlashPromotionSessionService.list();
        return CommonResult.success(smsFlashPromotionSessions);
    }

    /**
     * Description:获取全部可选场次及其数量
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @GetMapping("/selectList")
    public CommonResult selectList(@RequestParam Integer flashPromotionId) {
        List<SmsFlashPromotionSessionDetail> details = smsFlashPromotionSessionService.selectList(flashPromotionId);
        return CommonResult.success(details);
    }

    /**
     * Description:添加场次
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionService.create(smsFlashPromotionSession);
        return CommonResult.success();
    }

    /**
     * Description:删除场次
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        smsFlashPromotionSessionService.delete(id);
        return CommonResult.success();
    }

    /**
     * Description:修改启用状态
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateByStatus(@PathVariable Integer id, @RequestParam Integer status) {
        smsFlashPromotionSessionService.updateByStatus(id, status);
        return CommonResult.success();
    }

    /**
     * Description:修改场次
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Integer id, @RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionService.update(id,smsFlashPromotionSession);
        return CommonResult.success();
    }

    /**
     * Description:获取场次详情
     * date: 2022/4/4 10:00
     *
     * @author: chp
     * @since JDK 1.8
     */
    @GetMapping("/{id}")
    public CommonResult findOne(@PathVariable Integer id) {
        SmsFlashPromotionSession one = smsFlashPromotionSessionService.findOne(id);
        return CommonResult.success(one);
    }

}
